﻿
@{
	ViewBag.Title = "ApplicationDetailed";
	Layout = "~/Views/Shared/_Index.cshtml";
	var opr = Newtouch.Common.Operator.OperatorProvider.GetCurrent();
}

<form name="form1">
	<div class="panel panel-default">
		<table class="form">
			<tr>
				<th class="formTitle" id="thCZRQ">结算日期：</th>
				<td class="formValue" colspan="2">
					<input id="ksrq" type="text" class="form-control input-wdatepicker formClearIgnore" style="width:130px; float:left;" value="@DateTime.Now.ToString("yyyy-MM-01")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
					<span style="margin-left:2%;float:left;">—</span>
					<input id="jsrq" type="text" class="form-control input-wdatepicker formClearIgnore" style="width :130px;float:left;margin-left:2%;" value="@DateTime.Now.ToString("yyyy-MM-dd")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
				</td>
				<th class="formTitle">清算类型：</th>
				<td class="formValue">
					<select class="form-control" id="jslx" style="width:140px;"></select>
				</td>
				<th class="formTitle">险种类型：</th>
				<td class="formValue">
					<select class="form-control" id="xzlx" style="width:140px;"></select>
				</td>
				<td>
					<input type="button" id="btn_search_tj" class="btn btn-primary btn-md" style="margin-left:10px;width:40px;" value="统计" />
					<input type="button" id="btn_search_dmx" class="btn btn-primary btn-md" style="margin-left:10px;width:80px;" value="开始明细对账" />
				</td>
			</tr>
		</table>
	</div>



	<div class="gridPanel" style="width:98%">
		<table id="gridJSList"></table>
		<div id="gridPager"></div>
	</div>

	<div class="gridPanel" style="width:98%">
		<table id="gridJSList1"></table>
		<div id="gridPager1"></div>
	</div>


</form>

<script>
    $(function () {
        //浏览器窗口调整大小时重新加载jqGrid的宽
        $(window).resize(function () {
            initLayout("MyTabGrid");
        });
		getclrtypeList();
		getinsutypeList();
        //结算主记录
        gridJSListData();
        gridJSListData1();
    });


	function getclrtypeList() {

		$.ajax({
			type: "POST",
			url: "/DaySettleManage/DaySettle/Getclr_type",
			//data: { mllx: mzlx },
			dataType: "json",
			async: false,
			success: function (ajaxresp) {

				$.each(ajaxresp, function () {
					var option = "<option value='" + this.value + "'>" + this.label + "</option>";
					$("#jslx").append(option);
				});
			}
		});
	}

	function getinsutypeList() {

		$.ajax({
			type: "POST",
			url: "/DaySettleManage/DaySettle/Getinsutype",
			//data: { mllx: mzlx },
			dataType: "json",
			async: false,
			success: function (ajaxresp) {

				$.each(ajaxresp, function () {
					var option = "<option value='" + this.value + "'>" + this.label + "</option>";
					$("#xzlx").append(option);
				});
			}
		});
	}

    function gridJSListData() {
        var gridSort = 'CreateTime asc';
        var $gridJsList = $("#gridJSList");
        $gridJsList.dataGrid({
            //postData: getSearchPostData(),
			height: 300,
            url: "",
            colModel: [
                { label: '个人编码', name: 'grbm', width: 100, align: 'left' },
                { label: '就诊ID', name: 'jzid', width: 100, align: 'left' },
                { label: '结算ID', name: 'jsid', width: 100, align: 'left' },
                { label: '姓名', name: 'xm', width: 100, align: 'left' },
				{
					label: '医保结算日期', name: 'ybjsrq', width: 100, align: 'left',
					formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' } },
                { label: '总费用', name: 'zfy', width: 100, align: 'left' },
				{ label: '基金支付金额', name: 'jjzfje', width: 100, align: 'left' },
				{ label: '共济支付金额', name: 'gjje', width: 100, align: 'left' },
                { label: '是否退费', name: 'sftf', width: 100, align: 'left' },
                { label: '报销类型', name: 'bxlx', width: 100, align: 'left' },
                { label: '身份证', name: 'sfz', width: 100, align: 'left' },
                { label: '收据编号', name: 'sjh', width: 100, align: 'left' },
                { label: '清算类别', name: 'qslb', width: 100, align: 'left' },
                { label: '险种', name: 'xz', width: 100, align: 'left' },
            ],
            //pager: "#gridPager",
            //sortname: gridSort,
			unwritten: false,
			viewrecords: true,
			//footerrow: true,
			//userDataOnFooter: true,
			loadComplete: function () {

				var gridData = $("#gridJSList").jqGrid('getGridParam', 'data');

				//$("#gridJSList").jqGrid('footerData', 'set', { name: "count", count: gridData.length });

			},
            onSelectRow_page: function (rowid) {
                //console.log(rowid);
            },
            gridComplete: function (gridJszbList) {
                //jszbList = null;
                //if (gridJszbList && gridJszbList.rows) {
                //    jszbList = gridJszbList.rows;
                //}
            }
        });

        //统计按钮点击事件
        $("#btn_search_tj").click(function () {
			$('#gridJSList').jqGrid("clearGridData");//先清空明细
            $gridJsList.jqGrid('setGridParam', {
				postData: { ksrq: $("#ksrq").val(), jsrq: $("#jsrq").val(), jslx: $("#jslx").val(), xzlx: $("#xzlx").val() },
				url: '/DaySettleManage/DaySettle/GetQsmx',
                //page: 1,
            }).trigger('reloadGrid');
        });
    }

	$("#btn_search_dmx").click(function () {

		var ksrq = $("#ksrq").val();
		var jsrq = $("#jsrq").val();
		var ts = Date.parse(jsrq) - Date.parse(ksrq)+1;
		//if (ts >= 11) {
		//	$.modalAlert("间隔时间大于10天，清算明细对账", 'warning');
		//	return false;
		//}

		var predata = {
			hisId : "",
			operatorId : '@(opr.rygh)',
			operatorName : '@(opr.UserName)',
			insuplc_admdvs : "",
			stmt_begndate: $("#ksrq").val(),
			stmt_enddate: $("#jsrq").val(),
			insutype: $("#xzlx").val(),
			clr_type: $("#jslx").val(),
			setl_optins : "",
			medfee_sumamt : 0.00,
			fund_pay_sumamt : 0.0,
			acct_pay : 0.00,
			fixmedins_setl_cnt : 0,
			fileName : "fymxsc"
		};
		var refinfo;
		$.ajax({
			type: "POST",
			url: "http://127.0.0.1:33333/api/YiBao/ReconciliationDetail_3202",
			data: predata,
			dataType: "json",
			async: false,
			success: function (data) {
				refinfo = eval('(' + data + ')');
				//console.log(refinfo);
			}
		});

		if (refinfo) {
			if (refinfo.result && refinfo.result.length>0) {
				$('#gridJSList1').jqGrid("clearGridData");//先清空明细
				$('#gridJSList1').jqGrid('setGridParam', {
					postData: { ksrq: $("#ksrq").val(), jsrq: $("#jsrq").val(), jslx: $("#jslx").val(), xzlx: $("#xzlx").val() },
					url: '/DaySettleManage/DaySettle/GetQsmx_1',
					//page: 1,
				}).trigger('reloadGrid');
			}
		} else {

		}

	});

    function gridJSListData1() {
        var gridSort = 'CreateTime asc';
        var $gridJsList1 = $("#gridJSList1");
        $gridJsList1.dataGrid({
            //postData: getSearchPostData(),
            height: 200,
            url: "",
            colModel: [
                { label: '人员ID', name: 'ryid', width: 100, align: 'left' },
                { label: '就诊ID', name: 'jzid', width: 100, align: 'left' },
                { label: '结算ID', name: 'jsid', width: 100, align: 'left' },
                { label: '对账结果', name: 'dzjg', width: 100, align: 'left' },
                { label: '备注', name: 'bz', width: 100, align: 'left' },
                { label: '医疗费总额', name: 'ylfze', width: 100, align: 'left' },
                { label: '基金支付总额', name: 'jjzfze', width: 100, align: 'left' },
                { label: '个人账户支付总额', name: 'grzhzfze', width: 100, align: 'left' },
                { label: '发送方报文ID', name: 'fsfbwid', width: 100, align: 'left' },
                { label: '退费结算标志', name: 'tfjsbz', width: 100, align: 'left' },
            ],
            //pager: "#gridPager1",
            //sortname: gridSort,
			viewrecords: true,
			footerrow: true,
			userDataOnFooter: true,
			loadComplete: function () {

				var gridData = $("#gridJSList1").jqGrid('getGridParam', 'data');

				$("#gridJSList1").jqGrid('footerData', 'set', { name: "count", count: gridData.length });

			},
            onSelectRow_page: function (rowid) {
               // console.log(rowid);
            },
            gridComplete: function (gridJszbList) {
                //jszbList = null;
                //if (gridJszbList && gridJszbList.rows) {
                //    jszbList = gridJszbList.rows;
                //}
            }
        });

        //查询事件
        $("#btn_search_tj").click(function () {
			$('#gridJSList1').jqGrid("clearGridData");//先清空明细
			$gridJsList1.jqGrid('setGridParam', {
				postData: { ksrq: $("#ksrq").val(), jsrq: $("#jsrq").val(), jslx: $("#jslx").val(), xzlx: $("#xzlx").val()},
				url: '/DaySettleManage/DaySettle/GetQsmx_1',
                //page: 1,
            }).trigger('reloadGrid');
        });
    }

</script>

